<?php

use think\migration\Seeder;

class PolicyConsult extends Seeder
{
    /**
     * Run Method.
     *
     * Write your database seeder using this method.
     *
     * More information on writing seeders is available here:
     * http://docs.phinx.org/en/latest/seeding.html
     */
    public function run()
    {

        $faker = Faker\Factory::create('zh_CN');
        $data = [];
        // 循环生成50条数据
        for ($j = 0; $j < 5; $j++) {
            $data[] = [
                'title'      => $faker->title(100),
                'create_time'  => time(),
            ];
        }
        \think\Db::name('policy_cate')->insertAll($data);
        $data = [];
        // 循环生成50条数据
        for ($j = 0; $j < 50; $j++) {
            $title = [];
            for ($i =0; $i<3;$i++){
                $title[] = $faker->title;
            }
            $mag = [];
            $in = [0,1,3];
            for ($i =0; $i<$in[array_rand($in)];$i++){
                $mag[] = "http://placeimg.com/1000/1000";
            }
            $mag= [
                'type' => count($mag),
                'img' => $mag,
            ];
            $data[] = [
                'title'      => $faker->title(100),
                'cate_id'     => $faker->numberBetween(1,5),
                'tags'      => serializeByArray($title),
                'change_time'  => time(),
                'content'      => $faker->realText,
                'auth'      => $faker->title,
                'user_id'      => $faker->numberBetween(1,2333),
                'page_view'       => $faker->numberBetween(1,2333),
                'init_view'       => $faker->numberBetween(1,2333),
                'list_style'      => serializeByArray($mag),
                'cover_link'   => "http://placeimg.com/1000/1000",
                'top'   => $faker->numberBetween(0,1),
                'home'   => serializeByArray(['show'=>($faker->numberBetween(1,30)>15),'img'=>'http://placeimg.com/1000/1000']),
                'newest'   => $faker->numberBetween(0,1),
                'sort'     => $faker->numberBetween(0,5),
                'publish'      => $faker->numberBetween(0,1,2),
                'create_time'  => time(),
            ];
        }
        \think\Db::name('policy_consult')->insertAll($data);
    }
}